package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.BaseUserRole;
import com.briup.jz.bean.BaseUserRoleExample;
import com.briup.jz.dao.BaseUserRoleMapper;
import com.briup.jz.service.BaseUserRoleService;
import com.briup.jz.utils.CustomerException;

@Service
public class BaseUserRoleServiceImpl implements BaseUserRoleService {

	@Autowired
	private BaseUserRoleMapper baseUserRoleMapper;
	@Override
	public void saveOrUpdate(BaseUserRole baseUserRole) throws CustomerException {
		// TODO Auto-generated method stub
		if(baseUserRole.getId()!=null) {
			baseUserRoleMapper.updateByPrimaryKey(baseUserRole);
		} else {
			baseUserRoleMapper.insert(baseUserRole);
		}
	}

	@Override
	public List<BaseUserRole> query(Long Id) {
		BaseUserRoleExample example = new BaseUserRoleExample();
		if(Id!=null){
			example.createCriteria().andIdEqualTo(Id);
		}
		List<BaseUserRole> list = baseUserRoleMapper.selectByExample(example);
		return list;
	}

	@Override
	public void deleteById(long id) throws CustomerException {
		BaseUserRole baseUserRole = baseUserRoleMapper.selectByPrimaryKey(id);
		if(baseUserRole == null) {
			throw new CustomerException("要删除的分类信息不存在");
		}
		baseUserRoleMapper.deleteByPrimaryKey(id);

	}

	@Override
	public void updateByUserId(Long userId, Long roleId) {

		baseUserRoleMapper.updateByUserId(userId,roleId);
	}


}
